"""
pd读excel时候能读出各种类型
"""
from datetime import datetime
from typing import Union, List

from pandas import Series, Timestamp
import pandas as pd
import numpy as np

from bct.tools.common.bct_util import get_logger

logger = get_logger("pd_excel_reader")


def process_data(pd_data: Union[float, int, str, Series, Timestamp, datetime]) -> Union[List, None]:
    """
    复杂，懒得解释
    :param pd_data:
    :return:
    """
    if isinstance(pd_data, Series):
        ret = set()
        for obj in pd_data:
            if obj and not pd.isna(obj):
                ret.add(obj)
        return list(ret)
    elif pd.isna(pd_data):
        return [None]
    elif isinstance(pd_data, Timestamp) or isinstance(pd_data, datetime):
        return [pd_data]
    elif isinstance(pd_data, str):
        return [pd_data]
    else:
        type_arr = type(pd_data)
        if type_arr in [float, int, np.int32, np.int64, np.float32, np.float64]:
            if np.isnan(pd_data):
                return [None]
            else:
                return [str(pd_data)]
        else:
            logger.warning("未知的类型 %s" % type_arr)
    return [None]
